﻿using System.Linq;

namespace Basmus.Conel
{
    public class StringArrayBinding : Binding
    {
        public StringArrayBinding() : base(typeof(string))
        {
            
        }

        public override object[] GetElements(object container)
        {
            if (container == null)
                return null;

            var elements = (string[])container;
            return elements.Cast<object>().ToArray();
        }

        public override object GetContainer(object[] elements)
        {
            if (elements == null)
                return null;

            var container = elements.Cast<string>().Select(x => x ?? string.Empty).ToArray();
            return container;
        }
    }
}